package xyz.xtt.pay.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import xyz.xtt.common.response.ApiResult;
import xyz.xtt.pay.api.enums.PayOrderBusinessTypeEnum;
import xyz.xtt.pay.client.response.BusinessOrderResponse;
import xyz.xtt.pay.client.response.PayOrderResponse;
import xyz.xtt.pay.response.TopConsumeResponse;
import xyz.xtt.pay.service.INftOrderService;
import xyz.xtt.pay.service.IPayOrderService;
import xyz.xtt.pay.service.ITblBusinessOrderService;
import xyz.xtt.pay.service.ITblPayOrderService;
import xyz.xtt.pay.vo.OrderVo;

@Tag(name = "资产管理", description = "订单管理")
@RefreshScope
@Slf4j
@RequestMapping("/api/nft/pay")
@RestController
public class InnerPayController {
	@Autowired
	private INftOrderService nftOrderService;
	@Autowired
	private IPayOrderService iPayOrderService;
	@Autowired
	private ITblPayOrderService iTblPayOrderService;
	@Autowired
	private ITblBusinessOrderService iTblBusinessOrderService;

	@Operation(summary = "豪情榜")
	@GetMapping("/get_top_con")
	public ApiResult<TopConsumeResponse> getTopConsume(@RequestHeader("uid") Long uid) {
		log.info("/api/nft/pay/get_top_con uid:{}", uid);
		return ApiResult.ok(iPayOrderService.getHotConsume(uid));
	}

	/**
	 * xyz.xtt.exchange.controller.PayOrderController.list(String, Integer, Integer)
	 * 
	 * @param uid
	 * @param currPage
	 * @param pageSize
	 * @return
	 */
	@Operation(summary = "订单列表")
	@GetMapping("/list")
	public ApiResult<List<OrderVo>> list(@RequestHeader("uid") String uid, @RequestParam(defaultValue = "1") Integer currPage,
			@RequestParam(defaultValue = "10") Integer pageSize) {
		log.info("/api/nft/pay/list uid:{},currPage:{},pageSize:{}", uid, currPage, pageSize);
		Long uidL = Long.valueOf(uid);
		return ApiResult.ok(iPayOrderService.getOrderListByPayOrder(uidL, currPage, pageSize));
	}

	/**
	 * 查询支付单状态
	 * 
	 * @param businessRefId
	 * @param businessType
	 * @return
	 */
	@GetMapping("/queryPayStatus")
	public ApiResult<PayOrderResponse> queryPayStatus(Long businessRefId, Integer businessType) {
		log.info("/api/nft/pay/queryPayStatus businessRefId:{},businessType:{}", businessRefId, businessType);
		PayOrderResponse queryPayStatus = iPayOrderService.queryPayStatus(businessRefId, businessType);
		return ApiResult.ok(queryPayStatus);
	}

//	@Operation(summary = "支付订单状态确认")
//	@PostMapping("/confirmPayStatus")
//	public ApiResult<Boolean> confirmPayStatus(@RequestBody @Valid ConfirmPayOrderRequest confirmRequest) {
//		log.info("/api/nft/pay/confirmPayStatus body:{}", JSONUtil.toJsonStr(confirmRequest));
//		return ApiResult.ok(nftOrderService.confirmPayStatus(confirmRequest));
//	}

	@PostMapping("/mintAfterUpdateResult")
	public ApiResult<Boolean> mintAfterUpdateResult(Long payOrderId, Long transactionOrderId) {
		log.info("/api/nft/pay/mintAfterUpdateResult payOrderId:{},transactionOrderId:{}", payOrderId, transactionOrderId);
		boolean mintAfterUpdateResult = iTblPayOrderService.mintAfterUpdateResult(payOrderId, transactionOrderId);
		return ApiResult.ok(mintAfterUpdateResult);
	}

	@GetMapping("/businessOrderInfoWithId")
	public ApiResult<BusinessOrderResponse> businessOrderInfoWithId(Long businessOrderId) {
		log.info("/api/nft/pay/businessOrderInfoWithId businessOrderId:{}", businessOrderId);
		BusinessOrderResponse response = iTblBusinessOrderService.businessOrderInfoWithId(businessOrderId);
		return ApiResult.ok(response);
	}

	@GetMapping("/infoPayOrderWithBusinessRefId")
	public ApiResult<PayOrderResponse> infoPayOrderWithBusinessRefId(String businessRefId, PayOrderBusinessTypeEnum businessType) {
		log.info("/api/nft/pay/infoPayOrder businessRefId:{},businessType:{}", businessRefId, businessType);
		PayOrderResponse infoPayOrder = iTblPayOrderService.infoPayOrderWithBusinessRefId(businessRefId, businessType);
		return ApiResult.ok(infoPayOrder);
	}

}
